<template>
  <div class="questions-check">
    <!-- 表单区域 -->
    <el-form :model="checkForm" ref="checkFormRef">
      <el-form-item>
        <el-radio v-model="checkForm.chkState" :label="1">通过</el-radio>
        <el-radio v-model="checkForm.chkState" :label="2">拒绝</el-radio>
      </el-form-item>

      <el-form-item>
        <el-input type="textarea" v-model="checkForm.chkRemarks" placeholder="请选择审核意见"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onClose">取 消</el-button>
      <el-button type="primary" @click="onConfirm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'QuestionsCheck',
  props: {
    checkForm: {
      type: Object,
      required: true
    }
  },
  data() {
    return {}
  },

  methods: {
    // 点击确认完成请求
    async onConfirm() {
      if (!this.checkForm.chkRemarks.length) return this.$message.warning('请输入审核意见')
      try {
        await choiceCheck(this.checkForm)
        this.$message.success('操作成功')
        // 同步审核状态到父组件
        this.$emit('updata-chkState')
        this.checkForm.chkState = 1
        this.checkForm.chkRemarks = ''
      } catch (error) {
        console.log(error)
      }

      // 关闭弹框
      this.$emit('close')
    },

    // 点击取消关闭弹窗并重置表单
    onClose() {
      this.$emit('close')
      this.checkForm.chkState = 1
      this.checkForm.chkRemarks = ''
    }
  }
}
</script>

<style scoped lang='scss'>
.questions-check {
  .el-form {
    margin-bottom: 50px;
  }
  .el-form-item {
    margin-bottom: 18px;
  }
  .dialog-footer {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
